package su.jet.common.irc.domain;

import java.io.Serializable;

@SuppressWarnings("serial")
public class User implements Serializable{

	private String nickName;
	private String password;
	
	public User(String nickName) {
		this.nickName = nickName;
	}
	
	public User(String nickName, String password) {
		this(nickName);
		this.password = password;
	}

	
	//[DF] XXX: It is not reasonable to have not equal users with equal names, but different passwords
	// isn't it?
	@Override
	public boolean equals(Object obj) {
		if (!(obj instanceof User)) 
			return false;
		
		User compareUser = (User)obj;
		if (!(compareUser.nickName.equals(this.nickName)))
			return false;
				
		return true;
	}
	
	//[DF] XXX: It is not reasonable to have not equal users with equal names, but different passwords
	// isn't it? 
	@Override
	public int hashCode() {
		return this.nickName.hashCode();
	}
	
	public String getNickName() {
		return nickName;
	}
	
	public String getPassword() {
		return password;
	}

	//[DF] TODO: Probably better idea not to have getPassword, but validatePassword function, which 
	// encapsulates (probably with additional layer) logic of password validation
	public boolean verifyPassword(String password) {
		return this.password.equals(password);
	}	
}